﻿namespace GMS.Framework.Contract
{
    /// <summary>
    /// 用于BLL方法提传入条件
    /// </summary>
    public class Request : ModelBase
    {
        public Request()
        {
            PageSize = 5000;
        }

        public int Top
        {
            set
            {
                this.PageSize = value;
                this.PageIndex = 1;
            }
        }
        
        public int PageSize { get; set; }
        public int PageIndex { get; set; }
        public int PageTotalCount { get; set; }

        public int PageTotalPage
        {
            get {
                if (PageTotalCount > 0)
                {
                    return PageTotalCount % this.PageSize == 0 ? PageTotalCount / this.PageSize : PageTotalCount / this.PageSize + 1;
                }
                else
                {
                    return 0;
                }
            }
        }

        //融合其他分页控件的字段
        /// <summary>
        /// 每页行数
        /// </summary>
        public int rows { get; set; }
        /// <summary>
        /// 当前页
        /// </summary>
        public int page { get; set; }
        /// <summary>
        /// 排序列
        /// </summary>
        public string sidx { get; set; }
        /// <summary>
        /// 排序类型
        /// </summary>
        public string sord { get; set; }
        /// <summary>
        /// 总记录数
        /// </summary>
        public int records { get; set; }
        /// <summary>
        /// 总页数
        /// </summary>
        public int total
        {
            get
            {
                if (records > 0)
                {
                    return records % this.rows == 0 ? records / this.rows : records / this.rows + 1;
                }
                else
                {
                    return 0;
                }
            }
        }
    }
}
